<?php

namespace Biz\User;

use Base\Exception\NoRecordException;

class User extends \Base\BaseBiz
{
    /*
     * 获取列表
     */
    public static function getList($where, $now = 1, $size = 0)
    {
        $now = ($now > 0)?$now:1;
        $size = ($size > 0)?$size:\Util\Config::get('max_limit');
        $player_list = new \Orm\User\UserList();
        if (!empty($where)) {
            $player_list['where'] = $where;
        } else {
            $player_list['where'] = '';
        }
        $player_list['limit'] = $size;
        $player_list['offset'] = ($now - 1) * $size;
        $player_list['order'] = '`insert_time` desc';
        $player_list['key_by'] = 'id';
        $player_list->load();
        $result = array();
        $result['lists'] = $player_list['lists'];
        $result['total'] = $player_list['total'];
        return $result;
    }

    /*
     * 获取用户地址
     */
    public static function getAddressByUid($uid){
        $userAddress = new \Orm\UserAddress\UserAddressList();
        $userAddress->offsetSet('where','uid='.$uid);
        $userAddress->load();

        $userOrm = new \Orm\UserAddress\UserAddressClass();
        if($userAddress['lists']){
            $userOrm = $userAddress['lists'][0]??$userOrm;
        }

        return $userOrm;
    }
}
